<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Application Performance Monitoring (APM)</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="mongodb.tutorial.library.html">« Using the PHP Library for MongoDB (PHPLIB)</a></li>
      <li style="float: right;"><a href="mongodb.architecture.html">Driver Architecture and Internals »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="mongodb.tutorial.html">Tutorials</a></li>
    <li>Application Performance Monitoring (APM)</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="mongodb.tutorial.apm" class="chapter">
 <h1>Application Performance Monitoring (APM)</h1>


 <p class="para">
  The MongoDB driver contains an event subscriber API, which allows applications
  to monitor commands and internal activity pertaining to the
  <a href="https://github.com/mongodb/specifications/blob/master/source/server-discovery-and-monitoring/server-discovery-and-monitoring.rst" class="link external">&raquo;&nbsp;Server Discovery and Monitoring Specification</a>.
  This tutorial will demonstrate command monitoring using the
  <span class="classname"><a href="class.mongodb-driver-monitoring-commandsubscriber.html" class="classname">MongoDB\Driver\Monitoring\CommandSubscriber</a></span> interface.
 </p>

 <p class="para">
  The <span class="classname"><a href="class.mongodb-driver-monitoring-commandsubscriber.html" class="classname">MongoDB\Driver\Monitoring\CommandSubscriber</a></span>
  interface defines three methods: <code class="literal">commandStarted</code>,
  <code class="literal">commandSucceeded</code>, and <code class="literal">commandFailed</code>.
  Each of these three methods accept a single <code class="parameter">event</code>
  argument of a specific class for the respective event. For example, the
  <code class="literal">commandSucceeded</code>&#039;s <code class="parameter">$event</code> argument
  is a <span class="classname"><a href="class.mongodb-driver-monitoring-commandsucceededevent.html" class="classname">MongoDB\Driver\Monitoring\CommandSucceededEvent</a></span>
  object.
 </p>

 <p class="para">
  In this tutorial we will implement a subscriber that creates a list of all
  the query profiles and the average time they took.
 </p>

 <div class="section">
  <h2 class="title">Subscriber Class Scaffolding</h2>

  <p class="para">
   We start with the framework for our subscriber:
  </p>

  <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">QueryTimeCollector&nbsp;</span><span style="color: #007700">implements&nbsp;\</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">Driver</span><span style="color: #007700">\</span><span style="color: #0000BB">Monitoring</span><span style="color: #007700">\</span><span style="color: #0000BB">CommandSubscriber<br /></span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">commandStarted</span><span style="color: #007700">(&nbsp;\</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">Driver</span><span style="color: #007700">\</span><span style="color: #0000BB">Monitoring</span><span style="color: #007700">\</span><span style="color: #0000BB">CommandStartedEvent&nbsp;$event&nbsp;</span><span style="color: #007700">):&nbsp;</span><span style="color: #0000BB">void<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">commandSucceeded</span><span style="color: #007700">(&nbsp;\</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">Driver</span><span style="color: #007700">\</span><span style="color: #0000BB">Monitoring</span><span style="color: #007700">\</span><span style="color: #0000BB">CommandSucceededEvent&nbsp;$event&nbsp;</span><span style="color: #007700">):&nbsp;</span><span style="color: #0000BB">void<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">commandFailed</span><span style="color: #007700">(&nbsp;\</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">Driver</span><span style="color: #007700">\</span><span style="color: #0000BB">Monitoring</span><span style="color: #007700">\</span><span style="color: #0000BB">CommandFailedEvent&nbsp;$event&nbsp;</span><span style="color: #007700">):&nbsp;</span><span style="color: #0000BB">void<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
  </div>

 </div>

 <div class="section">
  <h2 class="title">Registering the Subscriber</h2>

  <p class="para">
   Once a subscriber object is instantiated, it needs to be registered with the
   driver&#039;s monitoring system. This is done by calling
   <span class="methodname"><a href="function.mongodb.driver.monitoring.addsubscriber.html" class="methodname">MongoDB\Driver\Monitoring\addSubscriber()</a></span> or
   <span class="methodname"><a href="mongodb-driver-manager.addsubscriber.html" class="methodname">MongoDB\Driver\Manager::addSubscriber()</a></span> to register
   the subscriber globally or with a specific Manager, respectively.
  </p>

  <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">\</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">Driver</span><span style="color: #007700">\</span><span style="color: #0000BB">Monitoring</span><span style="color: #007700">\</span><span style="color: #0000BB">addSubscriber</span><span style="color: #007700">(&nbsp;new&nbsp;</span><span style="color: #0000BB">QueryTimeCollector</span><span style="color: #007700">()&nbsp;);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
  </div>

 </div>

 <div class="section">
  <h2 class="title">Implementing the Logic</h2>

  <p class="para">
   With the object registered, the only thing left is to implement the logic
   in the subscriber class. To correlate the two events that make up a
   successfully executed command (commandStarted and commandSucceeded), each
   event object exposes a <code class="literal">requestId</code> field.
  </p>
  <p class="para">
   To record the average time per query shape, we will start by checking for a
   <code class="literal">find</code> command in the commandStarted event. We will then add
   an item to the <code class="literal">pendingCommands</code> property indexed by its
   <code class="literal">requestId</code> and with its value representing the query shape.
  </p>
  <p class="para">
   If we receive a corresponding commandSucceeded event with the same
   <code class="literal">requestId</code>, we add the duration of the event (from
   <code class="literal">durationMicros</code>) to the total time and increment the
   operation count.
  </p>
  <p class="para">
   If a corresponding commandFailed event is encountered, we just remove the
   entry from the <code class="literal">pendingCommands</code> property.
  </p>

  <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">QueryTimeCollector&nbsp;</span><span style="color: #007700">implements&nbsp;\</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">Driver</span><span style="color: #007700">\</span><span style="color: #0000BB">Monitoring</span><span style="color: #007700">\</span><span style="color: #0000BB">CommandSubscriber<br /></span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;</span><span style="color: #0000BB">$pendingCommands&nbsp;</span><span style="color: #007700">=&nbsp;[];<br />&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;</span><span style="color: #0000BB">$queryShapeStats&nbsp;</span><span style="color: #007700">=&nbsp;[];<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;Creates&nbsp;a&nbsp;query&nbsp;shape&nbsp;out&nbsp;of&nbsp;the&nbsp;filter&nbsp;argument.&nbsp;Right&nbsp;now&nbsp;it&nbsp;only<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;takes&nbsp;the&nbsp;top&nbsp;level&nbsp;fields&nbsp;into&nbsp;account&nbsp;*/<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">private&nbsp;function&nbsp;</span><span style="color: #0000BB">createQueryShape</span><span style="color: #007700">(&nbsp;array&nbsp;</span><span style="color: #0000BB">$filter&nbsp;</span><span style="color: #007700">)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">json_encode</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">array_keys</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$filter&nbsp;</span><span style="color: #007700">)&nbsp;);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">commandStarted</span><span style="color: #007700">(&nbsp;\</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">Driver</span><span style="color: #007700">\</span><span style="color: #0000BB">Monitoring</span><span style="color: #007700">\</span><span style="color: #0000BB">CommandStartedEvent&nbsp;$event&nbsp;</span><span style="color: #007700">):&nbsp;</span><span style="color: #0000BB">void<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(&nbsp;</span><span style="color: #0000BB">array_key_exists</span><span style="color: #007700">(&nbsp;</span><span style="color: #DD0000">'find'</span><span style="color: #007700">,&nbsp;(array)&nbsp;</span><span style="color: #0000BB">$event</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getCommand</span><span style="color: #007700">()&nbsp;)&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$queryShape&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">createQueryShape</span><span style="color: #007700">(&nbsp;(array)&nbsp;</span><span style="color: #0000BB">$event</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getCommand</span><span style="color: #007700">()-&gt;</span><span style="color: #0000BB">filter&nbsp;</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">pendingCommands</span><span style="color: #007700">[</span><span style="color: #0000BB">$event</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getRequestId</span><span style="color: #007700">()]&nbsp;=&nbsp;</span><span style="color: #0000BB">$queryShape</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">commandSucceeded</span><span style="color: #007700">(&nbsp;\</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">Driver</span><span style="color: #007700">\</span><span style="color: #0000BB">Monitoring</span><span style="color: #007700">\</span><span style="color: #0000BB">CommandSucceededEvent&nbsp;$event&nbsp;</span><span style="color: #007700">):&nbsp;</span><span style="color: #0000BB">void<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$requestId&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$event</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getRequestId</span><span style="color: #007700">();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(&nbsp;</span><span style="color: #0000BB">array_key_exists</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$requestId</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">pendingCommands&nbsp;</span><span style="color: #007700">)&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">queryShapeStats</span><span style="color: #007700">[</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">pendingCommands</span><span style="color: #007700">[</span><span style="color: #0000BB">$requestId</span><span style="color: #007700">]][</span><span style="color: #DD0000">'count'</span><span style="color: #007700">]++;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">queryShapeStats</span><span style="color: #007700">[</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">pendingCommands</span><span style="color: #007700">[</span><span style="color: #0000BB">$requestId</span><span style="color: #007700">]][</span><span style="color: #DD0000">'duration'</span><span style="color: #007700">]&nbsp;+=&nbsp;</span><span style="color: #0000BB">$event</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getDurationMicros</span><span style="color: #007700">();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;unset(&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">pendingCommands</span><span style="color: #007700">[</span><span style="color: #0000BB">$requestId</span><span style="color: #007700">]&nbsp;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">commandFailed</span><span style="color: #007700">(&nbsp;\</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">Driver</span><span style="color: #007700">\</span><span style="color: #0000BB">Monitoring</span><span style="color: #007700">\</span><span style="color: #0000BB">CommandFailedEvent&nbsp;$event&nbsp;</span><span style="color: #007700">):&nbsp;</span><span style="color: #0000BB">void<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(&nbsp;</span><span style="color: #0000BB">array_key_exists</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$event</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getRequestId</span><span style="color: #007700">(),&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">pendingCommands&nbsp;</span><span style="color: #007700">)&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;unset(&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">pendingCommands</span><span style="color: #007700">[</span><span style="color: #0000BB">$event</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getRequestId</span><span style="color: #007700">()]&nbsp;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">__destruct</span><span style="color: #007700">()<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach(&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">queryShapeStats&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$shape&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$stats&nbsp;</span><span style="color: #007700">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Shape:&nbsp;"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$shape</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"&nbsp;("</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$stats</span><span style="color: #007700">[</span><span style="color: #DD0000">'count'</span><span style="color: #007700">],&nbsp;</span><span style="color: #DD0000">")\n&nbsp;&nbsp;"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$stats</span><span style="color: #007700">[</span><span style="color: #DD0000">'duration'</span><span style="color: #007700">]&nbsp;/&nbsp;</span><span style="color: #0000BB">$stats</span><span style="color: #007700">[</span><span style="color: #DD0000">'count'</span><span style="color: #007700">],&nbsp;</span><span style="color: #DD0000">"µs\n\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></span><span style="color: #0000BB">$m&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;\</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">Driver</span><span style="color: #007700">\</span><span style="color: #0000BB">Manager</span><span style="color: #007700">(&nbsp;</span><span style="color: #DD0000">'mongodb://localhost:27016'&nbsp;</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Add&nbsp;the&nbsp;subscriber&nbsp;*/<br /></span><span style="color: #007700">\</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">Driver</span><span style="color: #007700">\</span><span style="color: #0000BB">Monitoring</span><span style="color: #007700">\</span><span style="color: #0000BB">addSubscriber</span><span style="color: #007700">(&nbsp;new&nbsp;</span><span style="color: #0000BB">QueryTimeCollector</span><span style="color: #007700">()&nbsp;);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Do&nbsp;a&nbsp;bunch&nbsp;of&nbsp;queries&nbsp;*/<br /></span><span style="color: #0000BB">$query&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;\</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">Driver</span><span style="color: #007700">\</span><span style="color: #0000BB">Query</span><span style="color: #007700">(&nbsp;[<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'region_slug'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'scotland-highlands'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'age'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;[&nbsp;</span><span style="color: #DD0000">'$gte'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">20&nbsp;</span><span style="color: #007700">]<br />]&nbsp;);<br /></span><span style="color: #0000BB">$cursor&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">executeQuery</span><span style="color: #007700">(&nbsp;</span><span style="color: #DD0000">'dramio.whisky'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$query&nbsp;</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$query&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;\</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">Driver</span><span style="color: #007700">\</span><span style="color: #0000BB">Query</span><span style="color: #007700">(&nbsp;[<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'region_slug'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'scotland-lowlands'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'age'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;[&nbsp;</span><span style="color: #DD0000">'$gte'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">15&nbsp;</span><span style="color: #007700">]<br />]&nbsp;);<br /></span><span style="color: #0000BB">$cursor&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">executeQuery</span><span style="color: #007700">(&nbsp;</span><span style="color: #DD0000">'dramio.whisky'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$query&nbsp;</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$query&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;\</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">Driver</span><span style="color: #007700">\</span><span style="color: #0000BB">Query</span><span style="color: #007700">(&nbsp;[&nbsp;</span><span style="color: #DD0000">'region_slug'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'scotland-lowlands'&nbsp;</span><span style="color: #007700">]&nbsp;);<br /></span><span style="color: #0000BB">$cursor&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">executeQuery</span><span style="color: #007700">(&nbsp;</span><span style="color: #DD0000">'dramio.whisky'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$query&nbsp;</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
  </div>

 </div>

</div>
</div></div></body></html>